package com.bee.plus.user.service;

import com.bee.plus.user.dto.User;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {

    /**
     * 模拟数据库数据
     */
    private static Map<Integer, User> dataMap;
    static {
        dataMap = new HashMap();
        dataMap.put(1, new User("admin", "123qweasd","133"));
        dataMap.put(2, new User("jack", "456","21"));
        dataMap.put(3, new User("alice", "789","12"));
        dataMap.put(4, new User("john", "123","2"));
    }

    public Flux list() {
        return Flux.fromIterable(dataMap.values());
    }


    public Mono getById(Integer id) {
        return Mono.justOrEmpty(dataMap.get(id));
    }

    public Mono del(Integer id) {
        return Mono.justOrEmpty(dataMap.remove(id));
    }

}
